package com.dtm.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dtm.R;
import com.dtm.client.Client;
import com.dtm.client.ClientConnectedThread;
import com.dtm.model.User;
import com.dtm.server.ClientThread;

public class AdapterUser extends ArrayAdapter<Client>{
	private LayoutInflater inflater;

	public AdapterUser(Context context, int resource, List<Client> objects) {
		super(context, resource, objects);
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Client item = getItem(position);
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_user, null);
		}
		TextView txtUsername = (TextView) convertView.findViewById(R.id.txt_name_player);
		txtUsername.setText(item.getName());
		ImageView avatar = (ImageView) convertView.findViewById(R.id.ibtn_avatar_player);
		avatar.setImageResource(User.getImage(item.getAvatar()));
		
		if (item.getStatus() == 1) {
			TextView txtStatusRdy = (TextView) convertView.findViewById(R.id.txt_status_ready);
			txtStatusRdy.setText("");
			TextView txtStatusHost = (TextView) convertView.findViewById(R.id.txt_status_host);
			txtStatusHost.setText("");
			TextView txtStatusConnected = (TextView) convertView.findViewById(R.id.txt_status_connected);
			txtStatusConnected.setText("CONNECTED");
		} else if (item.getStatus() == 2) {
			TextView txtStatusRdy = (TextView) convertView.findViewById(R.id.txt_status_ready);
			txtStatusRdy.setText("READY");
			TextView txtStatusHost = (TextView) convertView.findViewById(R.id.txt_status_host);
			txtStatusHost.setText("");
			TextView txtStatusConnected = (TextView) convertView.findViewById(R.id.txt_status_connected);
			txtStatusConnected.setText("");
		} else if (item.getStatus() == 3) {
			TextView txtStatusRdy = (TextView) convertView.findViewById(R.id.txt_status_ready);
			txtStatusRdy.setText("");
			TextView txtStatusHost = (TextView) convertView.findViewById(R.id.txt_status_host);
			txtStatusHost.setText("HOST");
			TextView txtStatusConnected = (TextView) convertView.findViewById(R.id.txt_status_connected);
			txtStatusConnected.setText("");
		}
		
		return convertView;
	}
//	public class ViewHodler{
//		private TextView title;
//		private ImageButton ibtn;
//		private TextView status;
//	}

}
